Skip to content

add enum Bitflags type#58

Open
ZXShady wants to merge 2 commits into
anjo76:masterfrom
ZXShady:bitflags
Open

add enum Bitflags type#58
ZXShady wants to merge 2 commits into
anjo76:masterfrom
ZXShady:bitflags

Conversation

@ZXShady

@ZXShady ZXShady commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

This is my first time modifying/extending a compiler (actually it is second after modifiying clang to add some poor man UFCS)

So excuse me for the quality of PR.

This adds enum bitflags which are enums with instead of contingous values, it will be conitgious bit flags

flag enum TextStyle {
    None, // 0
    Bold, // 1
    Italic, // 2
    Underlined, // 4
    Strikethrough // 8
};



bool main() 
{
    TextStyle style = TextStyle::Bold | TextStyle::Italic; // works without ERR cannot convert from int to TextStyle.
   if(style & TextStyle::Bold); // works
   if(!(style & TextStyle::Strikethrough)); // works
}

this also introduces a minor change to the bytecode format. Any previously saved bytecode to the new 1-byte flag marker. I am not sure if this is fine or should I pack it into some other variable for previous compatability? does angelscript gurantee script bytecode is always the same between major versions?

The test case is not the best but I also went ahead and used this pr in my own engine which uses angelscript and so far no crashes. so I hope it works and is up to the quality and the code format style.

ZXShady added 2 commits March 17, 2026 19:49
this implements the flag enum type that ensures ~, |, &, ^ return the same type.
@ZXShady ZXShady changed the title Bitflags add enum Bitflags type Mar 17, 2026
@anjo76

anjo76 commented Mar 17, 2026

Copy link
Copy Markdown
Owner

This is similar to an enhancement that I had planned to work on. I'll review your changes and incorporate to what I had planned when I get the time for it.

Bytecode serialization is only guaranteed to be compatible with the same code version, so it is not a problem that this changed.

@anjo76 anjo76 self-assigned this Mar 17, 2026
@anjo76 anjo76 added the enhancement New feature or request label Mar 17, 2026
@anjo76 anjo76 mentioned this pull request Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants